How to convert String to Char[] and Char[] to String in C# ?
This is a little tip which helps us to convert a C# char array to string and a string variable to char array.
1. We can convert a string variable to char array using a method called ToCharArray() in string class. Refer below,
string str = "I Love ASP.Net!"; char[] ch = str.ToCharArray(); for (int i = 0; i < ch.Length; i++) { Response.Write(ch[i] + "<BR>"); }
2. We can convert a character array back to string variable by using string class constructor. See below,
string strtarget = new string(ch); Response.Write(strtarget);
In the above code, ch is a type of char[] .
Happy Coding!!
|